home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 63140 / 63140.xpi / Rakefile < prev    next >
Text File  |  2009-01-23  |  3KB  |  98 lines

  1. require 'rexml/document'
  2. require 'digest/sha1'
  3. require 'rake/clean'
  4.  
  5. include REXML
  6. include FileUtils::Verbose
  7.  
  8. CLEAN.include ['*.xpi']
  9.  
  10. EXTENSION_NAME = 'tabundle'
  11. XPI_URL        = 'http://www.relucks.org/tabundle/tabundle.xpi'
  12. PROFILE_DIR    = '/Users/youhei/Library/Application Support/Firefox/Profiles/e2gtwgy4.development'
  13. MCCOY_DIR      = '/Users/youhei/Library/Application\ Support/McCoy/Profiles/977xwbo1.default'
  14. NSS_SIGN_DATA  = '/Applications/Firefox3.app/Contents/MacOS/nss_sign_data'
  15.  
  16. desc "create the xpi file and use the version number in the file name"
  17. task :xpi do
  18.   FileUtils.rm_rf Dir.glob('*.xpi')
  19.   file = xpi_filename
  20.   sh "zip -qr -9 #{file} *"
  21.   puts "create #{file}"
  22. end
  23.  
  24. desc "install to local profile directory"
  25. task :install => [:clean] do
  26.   install_path = "#{PROFILE_DIR}/extensions/#{extension_id}"
  27.   FileUtils.cp_r Dir.glob('*'), install_path
  28.   puts "copy #{install_path}"
  29. end
  30.  
  31. desc "uninstall from local profile directory"
  32. task :uninstall do
  33.   install_path = "#{PROFILE_DIR}/extensions/#{extension_id}"
  34.   FileUtils.rm_rf install_path
  35.   puts "remove #{install_path}"
  36. end
  37.  
  38. desc "update update.rdf"
  39. task :update_rdf => :xpi do
  40.   update_update_rdf
  41.   puts 'update update.rdf'
  42.   # sign_update_rdf
  43.   # puts 'sign update.rdf'
  44. end
  45.  
  46. desc "deploy xpi and update.rdf"
  47. task :deploy do
  48.   system "scp update.rdf tabundle.xpi  relucks.org:www/default/tabundle/"
  49. end
  50.  
  51. task :default => :xpi
  52.  
  53. def extension_id
  54.   open('install.rdf','r') do |file|
  55.     install_rdf_xmldoc = Document.new(file)
  56.     install_rdf_xmldoc.elements.each('RDF/Description/em:id') do |element|
  57.       return element.text
  58.     end
  59.   end
  60. end
  61.  
  62. def version_number
  63.   open('install.rdf') do |f|
  64.     install_rdf_xmldoc = Document.new(f.read)
  65.     install_rdf_xmldoc.elements.each('RDF/Description/em:version') do |element|
  66.       return element.text
  67.     end
  68.   end
  69. end
  70.  
  71. def xpi_filename
  72.   "#{EXTENSION_NAME}.xpi"
  73. end
  74.  
  75. def update_update_rdf
  76.   source = IO.read 'update.rdf'
  77.   source.sub!(/(em:version)="[^"]+"/, %(\\1="#{version_number}"))
  78.   source.sub!(/(em:updateHash)="[^"]+"/, %(\\1="#{xpi_hash}"))
  79.   source.sub!(/(em:updateLink)="[^"]+"/, %(\\1="#{XPI_URL}"))
  80.   open('update.rdf', 'w') { |f| f.puts source }
  81. end
  82.  
  83. def xpi_hash
  84.   'sha1:' + Digest::SHA1.hexdigest(open(xpi_filename).read)
  85. end
  86.  
  87. def sign_update_rdf
  88.   source = IO.read 'update.rdf'
  89.   source.sub!(/(em:signature)="[^"]+"/, %(\\1="#{sign}"))
  90.   open('update.rdf', 'w') { |f| f.puts source }
  91. end
  92.  
  93. # not working
  94. def sign
  95.   # http://ido.nu/kuma/2008/02/22/signing-firefox3-extension-updaterdf-with-spock/
  96.   `cat update.rdf | #{NSS_SIGN_DATA} #{MCCOY_DIR}`.strip
  97. end
  98.